1 using System;
2 using System.Collections.Generic;
3 using System.Globalization;
4 using System.Linq;
5 using System.Management;
6 using System.Security.Cryptography;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10
11 namespace SoftQuanLyNhaHang
12 {
13 class CauHinhHeThong
14 {
15
16 /// <summary>
17 /// Access routine for global variable.
18 /// </summary>
19 //1.000.000 hoac 1,000,000
20
21 //Mặc định dấu phẩy để tính toán là .
22 //dấu phân cách hàng nghìn là ,
23
24 private static string _phanCachHangNghin;
25 public static string PHAN_CACH_HANG_NGHIN
26 {
27 get
28 {
29 return _phanCachHangNghin;
30 }
31 set
32 {
33 _phanCachHangNghin = value;
34 }
35 }
36
37 //0.08 hoac 0,08
38 private static string _dauPhay;
39 public static string DAU_PHAY
40 {
41 get
42 {
43 return _dauPhay;
44 }
45 set
46 {
47 _dauPhay = value;
48 }
49 }
50
51 //Tieu de ngu hoa don ban hang
52 private static string _tieuDeNguHoaDonBanHang;
53 public static string TIEU_DE_NGU_HOA_DON_BAN_HANG
54 {
55 get
56 {
57 return _tieuDeNguHoaDonBanHang;
58 }
59 set
60 {
61 _tieuDeNguHoaDonBanHang = value;
62 }
63 }
64
65 //tieu de ngu hoa don nhap hang
66 private static string _tieuDeNguHoaDonNhapHang;
67 public static string TIEU_DE_NGU_HOA_DON_NHAP_HANG
68 {
69 get
70 {
71 return _tieuDeNguHoaDonNhapHang;
72 }
73 set
74 {
75 _tieuDeNguHoaDonNhapHang = value;
76 }
77 }
78
79 //Tieu de ngu hoa don ban hang
80 private static string _tieuDeHoaDonBanHang;
81 public static string TIEU_DE_HOA_DON_BAN_HANG
82 {
83 get
84 {
85 return _tieuDeHoaDonBanHang;
86 }
87 set
88 {
89 _tieuDeHoaDonBanHang = value;
90 }
91 }
92
93 //lưu thông tin khách hàng thanh toán
94 private static string _luuThongTinKhachMuaHang;
95 public static string LUU_THONG_TIN_KHACH_MUA_HANG
96 {
97 get
98 {
99 return _luuThongTinKhachMuaHang;
100 }
101 set
102 {
103 _luuThongTinKhachMuaHang = value;
104 }
105 }
106
107 //binh on gia ban
108 private static string _binhon_giaba;
109 public static string BINH_ON_GIA_BAN
110 {
111 get
112 {
113 return _binhon_giaba;
114 }
115 set
116 {
117 _binhon_giaba = value;
118 }
119 }
120
121 //ki hieu tien te
122 private static string _kiHieuTienTe;
123 public static string KI_HIEU_TIEN_TE
124 {
125 get
126 {
127 return _kiHieuTienTe;
128 }
129 set
130 {
131 _kiHieuTienTe = value;
132 }
133 }
134
135 //Kết nỗi cơ sở dữ liệu
136 private static bool _ketNoiCSDL;
137 public static bool KET_NOI_CSDL
138 {
139 get
140 {
141 return _ketNoiCSDL;
142 }
143 set
144 {
145 _ketNoiCSDL = value;
146 }
147 }
148
149
150 //in a4
151 private static int _print_Width;
152 public static int PRINT_WIDTH
153 {
154 get
155 {
156 return _print_Width;
157 }
158 set
159 {
160 _print_Width = value;
161 }
162 }
163
164 private static int _print_Height;
165 public static int PRINT_HEIGHT
166 {
167 get
168 {
169 return _print_Height;
170 }
171 set
172 {
173 _print_Height = value;
174 }
175 }
176
177 //THONG TIN CONG TY
178 private static string _tenCongTy;
179 public static string TEN_CONG_TY
180 {
181 get
182 {
183 return _tenCongTy;
184 }
185 set
186 {
187 _tenCongTy = value;
188 }
189 }
190
191 private static string _diaChi;
192 public static string DIA_CHI
193 {
194 get
195 {
196 return _diaChi;
197 }
198 set
199 {
200 _diaChi = value;
201 }
202 }
203
204 private static string _webSite;
205 public static string WEBSITE
206 {
207 get
208 {
209 return _webSite;
210 }
211 set
212 {
213 _webSite = value;
214 }
215 }
216
217 private static string _hotLine;
218 public static string HOTLINE
219 {
220 get
221 {
222 return _hotLine;
223 }
224 set
225 {
226 _hotLine = value;
227 }
228 }
229
230 //in hoa don sau khi ban
231 private static string _in_HoaDon_BanHang;
232 public static string IN_HOA_DON_SAU_KHI_BAN
233 {
234 get
235 {
236 return _in_HoaDon_BanHang;
237 }
238 set
239 {
240 _in_HoaDon_BanHang = value;
241 }
242 }
243
244 //ma thanh toan
245 private static string _barcodeThanhToanBanHang;
246 public static string BARCODE_THANH_TOAN_BAN_HANG
247 {
248 get
249 {
250 return _barcodeThanhToanBanHang;
251 }
252 set
253 {
254 _barcodeThanhToanBanHang = value;
255 }
256 }
257
258 //them moi kh
259 private static string _barcodeThemMoiKh;
260 public static string BARCODE_THEM_MOI_KHACH_HANG
261 {
262 get
263 {
264 return _barcodeThemMoiKh;
265 }
266 set
267 {
268 _barcodeThemMoiKh = value;
269 }
270 }
271
272 //don hang chua thanh toan
273 private static string _barcodeDonHangChuaThanhToan;
274 public static string BARCODE_DON_HANG_CHUA_THANH_TOAN
275 {
276 get
277 {
278 return _barcodeDonHangChuaThanhToan;
279 }
280 set
281 {
282 _barcodeDonHangChuaThanhToan = value;
283 }
284 }
285
286 //hiển thị kiểu số theo định dạng dấu phảy, hàng nghìn, hàng triệu vd 100.000,09 hoặc 100,000.07
287 public static string Format_HienThiKieuTien_CoDauPhanCachHangNghin(string strNumber, bool chuoi_TheoChuan_CSDL)
288 {
289 string txt;
290 int count = 0;
291 string truocDauPhay = "";
292 string sauDauPhay = "";
293
294 //string valReplace = "";
295 string[] tachChuoi;
296
297 if (CauHinhHeThong.DAU_PHAY == ".")
298 {
299 tachChuoi = strNumber.Split(new char[] { char.Parse(CauHinhHeThong.DAU_PHAY) });
300 foreach (string chuoi in tachChuoi)
301 {
302 count += 1;
303 if (count == 1) { truocDauPhay = chuoi; }
304 if (count == 2) { sauDauPhay = chuoi; }
305 }
306
307 if (count == 0)
308 {
309 truocDauPhay = strNumber;
310 }
311
312 truocDauPhay = truocDauPhay.Replace(CauHinhHeThong.PHAN_CACH_HANG_NGHIN, "");
313 truocDauPhay = decimal.Parse(truocDauPhay, CultureInfo.InvariantCulture).ToString("N0", new CultureInfo("en-US")).ToString();
314
315 if (count > 0)
316 {
317 if (sauDauPhay == "00")
318 {
319 txt = truocDauPhay;
320 }
321 else
322 {
323 if (sauDauPhay == "")
324 {
325 txt = truocDauPhay;
326 }
327 else
328 {
329 txt = truocDauPhay + CauHinhHeThong.DAU_PHAY + sauDauPhay;
330 }
331 }
332
333 }
334 else
335 {
336 txt = truocDauPhay;
337 }
338 }
339 else
340 {
341
342 //vd hiển thị 100,39 => CauHinhHeThong.DAU_PHAY
343 //cấu hình dấu phẩy là ,
344 //dấu phẩy là , trong csdl là .
345 //kiểm tra dấu , có trong chuỗi
346 //tồn tại dấu phẩy trong chuỗi
347 //=> là kiểu hiển thị
348 if(chuoi_TheoChuan_CSDL == true)
349 {
350 tachChuoi = strNumber.Split(new char[] { '.' });
351 }
352 else
353 {
354 tachChuoi = strNumber.Split(new char[] { ',' });
355 }
356
357 foreach (string chuoi in tachChuoi)
358 {
359 count += 1;
360 if (count == 1) { truocDauPhay = chuoi; }
361 if (count == 2) { sauDauPhay = chuoi; }
362 }
363
364 if (count == 0)
365 {
366 truocDauPhay = strNumber;
367 }
368
369 truocDauPhay = truocDauPhay.Replace(CauHinhHeThong.PHAN_CACH_HANG_NGHIN, "");
370 truocDauPhay = decimal.Parse(truocDauPhay, CultureInfo.InvariantCulture).ToString("N0", new CultureInfo("de-DE")).ToString();
371
372 if (count > 0)
373 {
374 if (sauDauPhay == "00")
375 {
376 txt = truocDauPhay;
377 }
378 else
379 {
380 if (sauDauPhay == "")
381 {
382 txt = truocDauPhay;
383 }
384 else
385 {
386 txt = truocDauPhay + CauHinhHeThong.DAU_PHAY + sauDauPhay;
387 }
388
389 }
390
391 }
392 else
393 {
394 txt = truocDauPhay;
395 }
396
397 }
398
399 return txt;
400
401
402 }
403
404 //Trả lại các số để lưu vào csdl
405 // dùng để chuẩn hóa kiểu số vd 1,000 => 1000
406 public static string Format_NumberKieuSo_DeTinhToan_HoacLuuLai(string strNumber)
407 {
408 string txt;
409
410 if (CauHinhHeThong.DAU_PHAY == ".")
411 {
412 //Replace dấu phân cách
413 txt = strNumber.Replace(",", "");
414 }
415 else
416 {
417 //dấu phẩy ,
418 //1.000.000,29
419 string[] tachChuoi = strNumber.Split(new char[] { ',' });
420 int count = 0;
421 string truocDauPhay = "";
422 string sauDauPhay = "";
423
424 foreach (string chuoi in tachChuoi)
425 {
426 count += 1;
427 if (count == 1) { truocDauPhay = chuoi; }
428 if (count == 2) { sauDauPhay = chuoi; }
429
430 }
431
432 if (count == 0)
433 {
434 truocDauPhay = strNumber;
435
436 txt = truocDauPhay.Replace(".", "");
437 }
438 else
439 {
440 truocDauPhay = truocDauPhay.Replace(".", "");
441 txt = truocDauPhay + '.' + sauDauPhay;
442 }
443
444 }
445
446 return txt;
447 }
448
449 //Dùng cho nhập text change
450 public static string DoFormat_NhapSoTrongText(string strNumber)
451 {
452 string txt;
453 int count = 0;
454
455 //1,000,000.39 => CauHinhHeThong.DAU_PHAY = '.'
456 if (strNumber.ToLower().Contains(CauHinhHeThong.DAU_PHAY))
457 {
458 //dem ky tu sau dau phay
459
460 string[] Words = strNumber.Split(new char[] { char.Parse(CauHinhHeThong.DAU_PHAY) });
461 //Đêm dấu phảy trong chuỗi
462 count = Words.Length;
463 }
464
465 if (count > 0)
466 {
467 //Không format giá tiền
468 txt = strNumber;
469 }
470 else
471 {
472 if (CauHinhHeThong.DAU_PHAY == ".")
473 {
474 //1,000,000.00
475 txt = decimal.Parse(strNumber, CultureInfo.InvariantCulture).ToString("N0", new CultureInfo("en-US")).ToString();
476 }
477 else
478 {
479 //1.000.000,00
480 txt = decimal.Parse(strNumber, CultureInfo.InvariantCulture).ToString("N0", new CultureInfo("de-DE")).ToString();
481 }
482 }
483
484 return txt;
485 }
486
487 //Hàm giới hạn chỉ cho nhập ký tự thuộc số trong text
488 public static void NhapSoTrongTextBox(object sender, KeyPressEventArgs e)
489 {
490
491 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != char.Parse(CauHinhHeThong.DAU_PHAY)))
492 {
493 e.Handled = true;
494 }
495
496 // only allow one decimal point
497 if ((e.KeyChar == char.Parse(CauHinhHeThong.DAU_PHAY)) && ((sender as TextBox).Text.IndexOf(char.Parse(CauHinhHeThong.DAU_PHAY)) > -1))
498 {
499 e.Handled = true;
500 }
501 }
502
503 //Hiển thị số có dấu phân cách hàng nghìn, 10000.00, 12345.67
504 public static string Format_SoDeHienThi(double _soKieuTinhToan, bool hienThiSoTienLaKieuTien)
505 {
506 string str_sokieuhienthi = string.Empty;
507
508 //Khai báo mảng trong số
509 string[] tachChuoi;
510
511 //Giá trị trước dấu phẩy
512 string truocDauPhay = string.Empty;
513 //Giá trị sau dấu phẩy
514 string sauDauPhay = string.Empty;
515
516 //Ép kiểu số thành chuỗi
517 string strNumber = _soKieuTinhToan.ToString();
518
519 tachChuoi = strNumber.Split(new char[] { '.' });
520 //Lấy các giá trị đã tách
521 int count = 0;
522 foreach (string chuoi in tachChuoi)
523 {
524 count += 1;
525 if (count == 1) { truocDauPhay = chuoi; }
526 if (count == 2) { sauDauPhay = chuoi; }
527 }
528
529
530 //Số không có dấu phẩy
531 if (count == 0)
532 {
533 truocDauPhay = strNumber;
534
535 }
536
537 if (CauHinhHeThong.DAU_PHAY == ".")
538 {
539 truocDauPhay = decimal.Parse(truocDauPhay, CultureInfo.InvariantCulture).ToString("N0", new CultureInfo("en-US")).ToString();
540 }
541 else
542 {
543 //dấu phẩy là , dấu phân cách là .
544 truocDauPhay = decimal.Parse(truocDauPhay, CultureInfo.InvariantCulture).ToString("N0", new CultureInfo("de-DE")).ToString();
545 }
546
547 //Có đấu phẩy
548 //sau dấu phẩy là 00 hoặc là null
549 if (sauDauPhay == "00" || sauDauPhay == "")
550 {
551 str_sokieuhienthi = truocDauPhay;
552 }
553 else
554 {
555 if (hienThiSoTienLaKieuTien == true)
556 {
557 str_sokieuhienthi = truocDauPhay;
558 }
559 else
560 {
561 //lay sau dau phay 3 ky tu
562 string them0vaodauphay = "0." + sauDauPhay;
563
564 them0vaodauphay = String.Format("{0:0.###}", double.Parse(them0vaodauphay));
565
566 sauDauPhay = them0vaodauphay.Replace("0.", "");
567
568 str_sokieuhienthi = truocDauPhay + CauHinhHeThong.DAU_PHAY + sauDauPhay;
569 }
570
571 }
572
573 return str_sokieuhienthi;
574 }
575
576 //đầu vào 1.555,55 or 1555.55
577 //hàm để tính toán format từ số có dấu phân cách hoặc không có dấu phân cách thanh số để tính toán, lưu vào csdl +-*/ fn
578 public static double Format_SoDeTinhToan(string _soStr, bool txtSoTuTextBox_OrRowDgv)
579 {
580 //1.777,456
581
582 //kiem tra khong phai la so thi tra ve 0
583 //neu null thi = 0
584 if (string.IsNullOrEmpty(_soStr))
585 {
586 return 0;
587 }
588
589 //10000.55 hoặc 10000,55
590 double dou_sokieutinhtoan = 0;
591
592 string soTruocDauPhay = string.Empty;
593 string soSauDauPhay = string.Empty;
594
595 string strSo = "0";
596
597 //mặc định dấu phẩy = ,
598 //Kiểm tra cấu hình dấu phẩy
599 if (CauHinhHeThong.DAU_PHAY == ".")
600 {
601 //soCoDauPhanCach = true
602 strSo = _soStr.Replace(",","");
603 }
604 else
605 {
606 //có dấu phẩy là ,
607
608 //1.000,123 soCoDauPhanCach = false
609 //100,21 soCoDauPhanCach = false
610 //Số lấy ra từ csdl hoặc số khai báo là kiểu double thì soCoDauPhanCach = true
611 //123.00 => soCoDauPhanCach = true (số từ csdl hoặc là kiểu double)
612 //dấu phẩy ,
613 //199,99 or 199.99
614
615 string[] tachChuoi;
616 //19000.89 , false
617 if (txtSoTuTextBox_OrRowDgv == true)
618 {
619 _soStr = _soStr.Replace(".","");
620 tachChuoi = _soStr.Split(new char[] { ',' });// 1000000.29
621 }
622 else
623 {
624 tachChuoi = _soStr.Split(new char[] { '.' });// 1000000.29
625 }
626
627 //string[] tachChuoi = _soStr.Split(new char[] { ',' });// 1000000.29
628 //string[] tachChuoi = _soStr.Split(new char[] { ',' });// 1000000.29
629 int count = 0;
630 string truocDauPhay = "";
631 string sauDauPhay = "";
632
633 foreach (string chuoi in tachChuoi)
634 {
635 count += 1;
636 if (count == 1) {
637 truocDauPhay = chuoi;
638 }//1.777
639 if (count == 2) {
640 sauDauPhay = chuoi;
641 }//456
642
643 }
644
645 //
646 if (count == 0 || count == 1)
647 {
648 //1.035.555 //dấu phẩy trong csdl
649 //strSo = _soDeHienThi;
650 strSo = _soStr.Replace(".", "");
651 }
652 else
653 {
654 //truocDauPhay = truocDauPhay.Replace(".", "");
655 //truocDauPhay = truocDauPhay.Replace(",", "");
656 strSo = truocDauPhay + "." + sauDauPhay;
657 }
658 }
659
660 if (txtSoTuTextBox_OrRowDgv == true)
661 {
662 ulong n;
663 bool isNumeric = ulong.TryParse(strSo, out n);
664
665 if (isNumeric == false)
666 {
667 return 0;
668 }
669 }
670
671 //Ép kiểu thành số để tính toán
672 dou_sokieutinhtoan = double.Parse(strSo);
673
674 return dou_sokieutinhtoan;
675 }
676
677 //hàm tính tiền thuế từ % thuế của một mặt hàng fn
678 public static double TinhTienThue_MotMatHang(double gianhap = 0, double soluong = 0, double thuePTram = 0, double ckpt = 0, double tienck = 0, string cktinhtheo = "PhanTram")
679 {
680 double dou_tienthue = 0;
681
682 if (cktinhtheo == "PhanTram")
683 {
684 dou_tienthue = (((gianhap * soluong) - (gianhap * soluong * ckpt / 100)) * thuePTram / 100);
685 }
686 else
687 {
688 dou_tienthue = ((gianhap * soluong - tienck) * thuePTram / 100);
689 }
690
691 return dou_tienthue;
692 }
693
694 //Hàm tính tiền chiết khấu
695 public static double TinhTienChietKhau(double gianhap = 0, double soluong = 0, double ckphantram = 0)
696 {
697 double dou_tienchietkhau = 0;
698
699 dou_tienchietkhau = gianhap * soluong * ckphantram / 100;
700
701 return dou_tienchietkhau;
702 }
703
704 //Hàm tính phần trăm chiết khấu
705 public static double TinhPhanTramChietKhau(double gianhap = 0, double soluong = 0, double tienchietkhau = 0)
706 {
707 double dou_phantramchietkhau = 0;
708
709 //lam tron sau dau phay la 5 so
710 dou_phantramchietkhau = Math.Round((tienchietkhau * 100) / (gianhap * soluong), 5);
711
712 return dou_phantramchietkhau;
713 }
714
715 //Hàm tính tổng một mặt hàng
716 public static double TinhTongMot_MatHang(double gianhap = 0, double soluong = 0, double ckPTram = 0, double tienCk = 0, string ckTinhTheo = "PhanTram", double thue = 0)
717 {
718 double tongmotmathang = 0;
719 double tongKhongThue = 0;
720 //mat hang co chiet khau
721 if (ckTinhTheo == "PhanTram")
722 {
723 tongKhongThue = (gianhap * soluong) - (gianhap * soluong * ckPTram / 100);
724 }
725 else
726 {
727 tongKhongThue = (gianhap * soluong - tienCk);
728 }
729
730 tongmotmathang = tongKhongThue + (tongKhongThue * thue / 100);
731
732 return tongmotmathang;
733 }
734
735 //hiển thị ngày tháng năm
736 public static string Format_HienThiNgayThangNam(string strDatetime, bool hienThiGioPhut)
737 {
738
739 if (strDatetime == null || strDatetime == "")
740 {
741 return "";
742 }
743
744 //-http://diendan.congdongcviet.com/threads/t201242::dinh-dang-ngay-thang-nam-trong-csharp.cpp
745 string ngay = "1";
746 string thang = "1";
747 string nam = "2017";
748
749 string gio = "00";
750 string phut = "00";
751 //string am_pm = "AM";
752
753 string ngayThangNam = "00/00/0000";
754
755 if (DateTime.Parse(strDatetime).Day < 10)
756 {
757 ngay = "0" + DateTime.Parse(strDatetime).Day.ToString();
758 }
759 else
760 {
761 ngay = DateTime.Parse(strDatetime).Day.ToString();
762 }
763
764 if (DateTime.Parse(strDatetime).Month < 10)
765 {
766 thang = "0"+ DateTime.Parse(strDatetime).Month.ToString();
767 }
768 else
769 {
770 thang = DateTime.Parse(strDatetime).Month.ToString();
771 }
772
773 if (DateTime.Parse(strDatetime).Year > 0)
774 {
775 nam = DateTime.Parse(strDatetime).Year.ToString();
776 }
777
778 //string ngayThangNam = DateTime.Parse(strDatetime).Day + "/" + DateTime.Parse(strDatetime).Month + "/" + DateTime.Parse(strDatetime).Year;// +" " + DateTime.Parse(strDatetime).Minute + ":" + DateTime.Parse(strDatetime).Second;
779 ngayThangNam = ngay + "/" + thang + "/" + nam;
780
781 if (DateTime.Parse(strDatetime).Hour < 10)
782 {
783 gio = "0" + DateTime.Parse(strDatetime).Hour.ToString();
784 }
785 else
786 {
787 gio = DateTime.Parse(strDatetime).Hour.ToString();
788 }
789
790 if (DateTime.Parse(strDatetime).Minute < 10)
791 {
792 phut = "0" + DateTime.Parse(strDatetime).Minute.ToString();
793 }
794 else
795 {
796 phut = DateTime.Parse(strDatetime).Minute.ToString();
797 }
798
799
800 if (hienThiGioPhut == true)
801 {
802 ngayThangNam = ngay + "/" + thang + "/" + nam + " " + gio + ":" + phut;
803 }
804
805
806 return ngayThangNam;
807 }
808
809 //Tính điểm tích lũy
810 public static double TinhDiemTichLuy(double tienThanhToan)
811 {
812 double dtl = 0;
813
814 //công thức tính điểm tích lý cần chỉnh lại trong file cấu hình
815 dtl = tienThanhToan * 10 / 100;
816
817 return dtl;
818 }
819
820
821 //Tính tổng tiền của một mặt hàng gồm 1 hoặc nhiều sản phẩm
822 //Hàm dành riêng cho form bán hàng (BanHang)
823 public static double BanHang_ThanhTien(double giaban, double soluong, double thue, double chietkhauPt)
824 {
825 double thanhtien = 0;
826
827 thanhtien = (soluong * giaban) - (soluong * giaban * chietkhauPt / 100) + (soluong * giaban * thue / 100);
828
829 return thanhtien;
830 }
831
832 /*
833
834 //hien thi combobox thue
835 public static void ComboBox_Thue(ComboBox name_cmbThue, string valueThue)
836 {
837 Dictionary<string, string> comboSource = new Dictionary<string, string>();
838 comboSource.Add("0", "0");
839 comboSource.Add("5", "5");
840 comboSource.Add("10", "10");
841 name_cmbThue.DataSource = new BindingSource(comboSource, null);
842 name_cmbThue.DisplayMember = "Value";
843 name_cmbThue.ValueMember = "Key";
844
845 name_cmbThue.SelectedValue = valueThue;
846 }
847 */
848 //Hiển thị trang thái của đơn hàng nhập hàng
849 public static string TrangThai_NhapHang(string trangThai)
850 {
851 string txtTrangThai = string.Empty;
852
853 switch (trangThai)
854 {
855 case "DonHangNoNCC":
856 {
857 txtTrangThai = "Nợ NCC";
858 break;
859 }
860 case "DaThanhToan":
861 {
862 txtTrangThai = "Đã thanh toán";
863 break;
864 }
865 case "HuyDonHang":
866 {
867 txtTrangThai = "Hủy đơn hàng";
868 break;
869 }
870 case "TamDung":
871 {
872 txtTrangThai = "Tạm dừng";
873 break;
874 }
875 case "NhapHang":
876 {
877 txtTrangThai = "Nhập hàng";
878 break;
879 }
880 case "Copy":
881 {
882 txtTrangThai = "Copy đơn hàng";
883 break;
884 }
885 default:
886 {
887 txtTrangThai = "?";
888 break;
889 }
890 }
891
892 return txtTrangThai;
893
894 }
895
896 public static string HienThiSoBanGhiTuA_DenB(int _PageSize, int _PageIndex, string _STT, string _TongSoBanGhi)
897 {
898 string txt = string.Empty;
899
900 if (_TongSoBanGhi == "0")
901 {
902 txt = "Hiển thị từ " + ((_PageIndex - 1) * _PageSize).ToString() + " đến " + _STT + " trong " + _TongSoBanGhi + " mục";
903 }
904 else
905 {
906 txt = "Hiển thị từ " + (((_PageIndex - 1) * _PageSize) + 1).ToString() + " đến " + _STT + " trong " + _TongSoBanGhi + " mục";
907 }
908
909
910 return txt;
911 }
912
913 //--http://www.ngoquangbon.name.vn/readprint.aspx?idBaiViet=de6ae438d17e09377bdc27e5ab19a25
914 public static string HienThiGiaTien_ThanhChu(decimal total)
915 {
916 try
917 {
918 string rs = "";
919 total = Math.Round(total, 0);
920 string[] ch = { "không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín" };
921 string[] rch = { "lẻ", "mốt", "", "", "", "lăm" };
922 string[] u = { "", "mươi", "trăm", "ngàn", "", "", "triệu", "", "", "tỷ", "", "", "ngàn", "", "", "triệu" };
923 string nstr = total.ToString();
924 int[] n = new int[nstr.Length];
925 int len = n.Length;
926
927 if (len > 15)
928 {
929 //return "###";
930 }
931
932 for (int i = 0; i < len; i++)
933 {
934 n[len - 1 - i] = Convert.ToInt32(nstr.Substring(i, 1));
935 }
936
937 for (int i = len - 1; i >= 0; i--)
938 {
939 if (i % 3 == 2)// số 0 ở hàng trăm
940 {
941 if (n[i] == 0 && n[i - 1] == 0 && n[i - 2] == 0) continue;//nếu cả 3 số là 0 thì bỏ qua không đọc
942 }
943 else if (i % 3 == 1) // số ở hàng chục
944 {
945 if (n[i] == 0)
946 {
947 if (n[i - 1] == 0) { continue; }// nếu hàng chục và hàng đơn vị đều là 0 thì bỏ qua.
948 else
949 {
950 rs += " " + rch[n[i]]; continue;// hàng chục là 0 thì bỏ qua, đọc số hàng đơn vị
951 }
952 }
953 if (n[i] == 1)//nếu số hàng chục là 1 thì đọc là mười
954 {
955 rs += " mười"; continue;
956 }
957 }
958 else if (i != len - 1)// số ở hàng đơn vị (không phải là số đầu tiên)
959 {
960 if (n[i] == 0)// số hàng đơn vị là 0 thì chỉ đọc đơn vị
961 {
962 if (i + 2 <= len - 1 && n[i + 2] == 0 && n[i + 1] == 0) continue;
963 rs += " " + (i % 3 == 0 ? u[i] : u[i % 3]);
964 continue;
965 }
966 if (n[i] == 1)// nếu là 1 thì tùy vào số hàng chục mà đọc: 0,1: một / còn lại: mốt 29/10/2017 Hàm đọc số tiền thành chữ trong C#
967 {
968 rs += " " + ((n[i + 1] == 1 || n[i + 1] == 0) ? ch[n[i]] : rch[n[i]]);
969 rs += " " + (i % 3 == 0 ? u[i] : u[i % 3]);
970 continue;
971 }
972 if (n[i] == 5) // cách đọc số 5
973 {
974 if (n[i + 1] != 0) //nếu số hàng chục khác 0 thì đọc số 5 là lăm
975 {
976 rs += " " + rch[n[i]];// đọc số
977 rs += " " + (i % 3 == 0 ? u[i] : u[i % 3]);// đọc đơn vị
978 continue;
979 }
980 }
981 }
982 rs += (rs == "" ? " " : ", ") + ch[n[i]];// đọc số
983 rs += " " + (i % 3 == 0 ? u[i] : u[i % 3]);// đọc đơn vị
984 }
985
986 if (rs[rs.Length - 1] != ' ')
987 {
988 rs += " đồng.";
989 }
990 else
991 {
992 rs += "đồng.";
993 }
994
995 if (rs.Length > 2)
996 {
997 string rs1 = rs.Substring(0, 2);
998 rs1 = rs1.ToUpper();
999 rs = rs.Substring(2);
1000 rs = rs1 + rs;
1001 }
1002 return rs.Trim().Replace("lẻ,", "lẻ").Replace("mươi,", "mươi").Replace("trăm,", "trăm").Replace("mười,",
1003 "mười");
1004 }
1005 catch
1006 {
1007 return "Số bạn nhập vào quá lớn";
1008 }
1009 }
1010
1011
1012 //--https://www.codeproject.com/Articles/38951/How-To-Hash-Data-Using-MD-and-SHA
1013 /// <summary>
1014 /// take any string and encrypt it using MD5 then
1015 /// return the encrypted data
1016 /// </summary>
1017 /// <param name="data">input text you will enterd to encrypt it</param>
1018 /// <returns>return the encrypted text as hexadecimal string</returns>
1019 public static string GetMD5HashData(string data)
1020 {
1021 //create new instance of md5
1022 MD5 md5 = MD5.Create();
1023
1024 //convert the input text to array of bytes
1025 byte[] hashData = md5.ComputeHash(Encoding.Default.GetBytes(data));
1026
1027 //create new instance of StringBuilder to save hashed data
1028 StringBuilder returnValue = new StringBuilder();
1029
1030 //loop for each byte and add it to StringBuilder
1031 for (int i = 0; i < hashData.Length; i++)
1032 {
1033 returnValue.Append(hashData[i].ToString());
1034 }
1035
1036 // return hexadecimal string
1037 return returnValue.ToString();
1038
1039 }
1040 //
1041 /// <summary>
1042 /// take any string and encrypt it using SHA1 then
1043 /// return the encrypted data
1044 /// </summary>
1045 /// <param name="data">input text you will enterd to encrypt it</param>
1046 /// <returns>return the encrypted text as hexadecimal string</returns>
1047 public static string GetSHA1HashData(string data)
1048 {
1049 //create new instance of md5
1050 SHA1 sha1 = SHA1.Create();
1051
1052 //convert the input text to array of bytes
1053 byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(data));
1054
1055 //create new instance of StringBuilder to save hashed data
1056 StringBuilder returnValue = new StringBuilder();
1057
1058 //loop for each byte and add it to StringBuilder
1059 for (int i = 0; i < hashData.Length; i++)
1060 {
1061 returnValue.Append(hashData[i].ToString());
1062 }
1063
1064 // return hexadecimal string
1065 return returnValue.ToString();
1066 }
1067 //
1068 /// <summary>
1069 /// encrypt input text using MD5 and compare it with
1070 /// the stored encrypted text
1071 /// </summary>
1072 /// <param name="inputData">input text you will enterd to encrypt it</param>
1073 /// <param name="storedHashData">the encrypted text stored on file or database ... etc</param>
1074 /// <returns>true or false depending on input validation</returns>
1075 private static bool ValidateMD5HashData(string inputData, string storedHashData)
1076 {
1077 //hash input text and save it string variable
1078 string getHashInputData = GetMD5HashData(inputData);
1079
1080 if (string.Compare(getHashInputData, storedHashData) == 0)
1081 {
1082 return true;
1083 }
1084 else
1085 {
1086 return false;
1087 }
1088 }
1089 //
1090 public static bool ValidateSHA1HashData(string inputData, string storedHashData)
1091 {
1092 //hash input text and save it string variable
1093 string getHashInputData = GetSHA1HashData(inputData);
1094
1095 if (string.Compare(getHashInputData, storedHashData) == 0)
1096 {
1097 return true;
1098 }
1099 else
1100 {
1101 return false;
1102 }
1103 }
1104 //
1105 //lay cpu id
1106 //kiem tra cpu id
1107 public static string getCPUID()
1108 {
1109 string cpuInfo = "";
1110 ManagementClass managClass = new ManagementClass("win32_processor");
1111 ManagementObjectCollection managCollec = managClass.GetInstances();
1112
1113 foreach (ManagementObject managObj in managCollec)
1114 {
1115 if (cpuInfo == "")
1116 {
1117 //Get only the first CPU's ID
1118 cpuInfo = managObj.Properties["processorID"].Value.ToString();
1119 break;
1120 }
1121 }
1122
1123 return cpuInfo;
1124 }
1125
1126 //
1127 }
1128 }